const path = require('path');

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = [{
    mode: 'development',
    context: __dirname,
    entry: {
        app: './src/index.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    devtool: 'eval',
    node: {
        // Resolve node module use of fs
        fs: "empty",
        Buffer: false,
        http: "empty",
        https: "empty",
        zlib: "empty"
    },
    resolve: {
        mainFields: ['module', 'main'],
        alias: {
            '@': path.join(__dirname, '..', 'src'), //"d:\SVN PROJ\diankeyuan\Web\src"
            '~': path.join(__dirname, '..', 'src'), //"d:\SVN PROJ\diankeyuan\Web\src"
        }
    },
    module: {
        rules: [{
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }, {
                test: /\.(png|gif|jpg|jpeg|svg|xml)$/,
                use: ['url-loader']
            },
            // {
            //     test: /\.json$/,
            //     loader: 'json-loader'
            // }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'src/index.html'
        }),
        new CopyWebpackPlugin([{
            from: 'src/data',
            to: 'data'
        }]),
        // Copy Cesium Assets, Widgets, and Workers to a static directory
        new CopyWebpackPlugin([{
            from: 'node_modules/cesium/Build/Cesium/Workers',
            to: 'Workers'
        }]),
        new CopyWebpackPlugin([{
            from: 'node_modules/cesium/Build/Cesium/ThirdParty',
            to: 'ThirdParty'
        }]),
        new CopyWebpackPlugin([{
            from: 'node_modules/cesium/Build/Cesium/Assets',
            to: 'Assets'
        }]),
        new CopyWebpackPlugin([{
            from: 'node_modules/cesium/Build/Cesium/Widgets',
            to: 'Widgets'
        }]),
        new webpack.DefinePlugin({
            // Define relative base path in cesium for loading assets
            CESIUM_BASE_URL: JSON.stringify('')
        })
    ],

    // development server options
    devServer: {
        contentBase: path.join(__dirname, "dist")
    }
}];